// add indexOf function in array for IE
if (!Array.indexOf) {
  Array.prototype.indexOf = function (obj, start) {
    for (var i = (start || 0); i < this.length; i++) {
      if (this[i] == obj) {
        return i;
      }
    }
    return -1;
  }
}
// end add indexOf function in array for IE
// Nhom cac ham xu ly danh sach thiet bi
function DetectBrowser()
{
	var browser=navigator.appName;
	//var b_version=navigator.appVersion;
	//var version=parseFloat(b_version);
	if (browser=="Microsoft Internet Explorer")
	{   		
			alert(MYUTILS_FUNCTION_SUPPORT); 	
	}
	else
	{
		//browser=="Netscape"|| (version>=4)
		//alert("It's time to upgrade your browser!");
	}
}
function CheckAllDevice(bCheck)
{
	if(typeof(bCheck) != "boolean")
	{
		bCheck = false;
	}
	
	if(bCheck)
	{
		// Check tat ca ne
		alert("Check All");		
	}
	else
	{
		// Bo check ha
		alert("Uncheck All");
	}
	$("#tbl_devicesList INPUT[type='checkbox']").attr("checked", bCheck);
}

function ShowDevice(bCheck, nID)
{
	if(typeof(bCheck) != "boolean")
	{
		bCheck = false;
	}
	
	if(typeof(nID) != "number")
	{
		nID = 0;
	}
	if(bCheck)
	{
		// Show device len ne
		alert("Show device ID:" + nID);
	}
	else
	{
		// Hide device ne
		alert("HIDE device ID:" + nID);
	}
}

function PanTo(nID)
{		
	if(typeof(nID) != "number")
	{
		nID = 0;
	}
	// Di chuyen toi devie nay ne
	alert("Pan to device ID:" + nID);	
}

// Nhom cac ham xu ly danh sach dia diem
function CheckAllLocation(bCheck)
{
	if(typeof(bCheck) != "boolean")
	{
		bCheck = false;
	}
	
	if(bCheck)
	{
		// Check tat ca ne
		alert("Check All Location");
	}
	else
	{
		// Bo check ha
		alert("Uncheck All location");
	}
	$("#tblLocationList INPUT[type='checkbox']").attr("checked", bCheck);
}

function ShowLocation(bCheck, nID)
{
	if(typeof(bCheck) != "boolean")
	{
		bCheck = false;
	}
	
	if(typeof(nID) != "number")
	{
		nID = 0;
	}
	if(bCheck)
	{
		// Show location len ne
		alert("Show location ID:" + nID);
	}
	else
	{
		// Hide location ne
		alert("HIDE location ID:" + nID);
	}	
}

function PanToLocation(nID)
{
	if(typeof(nID) != "number")
	{
		nID = 0;
	}
	// Di chuyen toi dia diem nay ne
	alert("Pan to location ID:" + nID);
}

function CreateLocationTongle(bCheck)
{
	if(typeof(bCheck) != "boolean")
	{
		bCheck = false;
	}
	
	if(bCheck)
	{
		// Tao dia diem ne
		alert(MYUTILS_CREATE_LOC_START);
	}
	else
	{
		// Khong tao dia diem nua
		alert(MYUTILS_CREATE_LOC_END);
	}
}

function DeleteLocation(nID)
{
	if(typeof(nID) != "number")
	{
		nID = 0;
	}
	// xoa dia diem ne
	alert("Delete location ID:" + nID);
}

// Nhom cac ham xu ly form xem lai
function ChangeTimeOption(nTime)
{	
	if(typeof(nTime) != "number")
	{
		nTime = parseInt(nTime);
	}	
	// Thay doi option time ne
	if(nTime != 1000)
	{
		alert("Hide Time Input");
	}
	else
	{
		alert("Show Time Input");
	}	
}

// Nhom cac ham xu ly chi tiet xem lai
function PanToTime(nID)
{		
	if(typeof(nID) != "number")
	{
		nID = 0;
	}
	// Di chuyen toi thoi diem nay ne
	alert("Pan to time ID:" + nID);	
}

function CheckPlay(bCheck)
{
	if(typeof(bCheck) != "boolean")
	{
		bCheck = false;
	}
	
	if(bCheck)
	{
		// Check tat ca ne
		alert("Playing");
	}
	else
	{
		// Bo check ha
		alert("Stop");
	}
}

function ShowDeviceFilter()
{
	// Hien thi form chon thiet bi.
}

function AnimationPlay()
{
	alert("start/stop animation");
}

function DayChange(sDate)
{
	alert('Load data of date: ' + sDate);
}

function CreateNewLocation(id, name, checked, lat1, lng1, lat2, lng2, description, userName, link, loc_type, address, contact, phone, amount, rad)
{    
    var obj = new Object();
        
    obj.id = id;
    obj.name = name;
    obj.checked = checked;
    obj.lat1 = lat1;
    obj.lng1 = lng1;
    obj.lat2 = lat2;
    obj.lng2 = lng2;
    obj.description = description;
    obj.userName = userName;    
    obj.link = link;
    obj.loc_type = loc_type;
    obj.address = address;
    obj.contact = contact;
    obj.phone = phone;
    obj.amount = amount;
    obj.rad = rad

    return(obj);
}
//function CreateUserInfo(display_vehicle, display_trktime, display_active, display_status, display_driver, display_distance, display_power, display_km_day) {
function CreateUserInfo() {
    var obj = new Object();

    obj.display_vehicle = 0;
    obj.display_trktime = 0;
    obj.display_active = 0;
    obj.display_status = 0;
    obj.display_driver = 0;
    obj.display_distance = 0;
    obj.display_power = 0;
    obj.display_km_day = 0;
        
    return obj;
}

// ĐậmPV: 2010-10-11 - Edit: thêm trạng thái nguồn 
function CreateNewDevice(name, driver, time, speed, distance, position, latitude, longitude, status, gps, satelline, id, checked, sLink, stoptime, losttime, driverphone, direction,sumdistance,input1,input2,input3,input4,input5,volume,fuel,power,power_id,active,trucktype,ad2,mapid)
{
    var obj=new Object();
    
    obj.name = name;// : Phương tiện;
    obj.driver = driver;// : Tài xế
    obj.time = time;// : Thời điểm
    obj.speed = speed;//: Vận tốc
    obj.distance = distance;//: khoảng cách.
    obj.position = position;// : vị trí xe.
    obj.latitude = latitude;
    obj.longitude = longitude;
    obj.status = status;
    obj.gps = gps;
    obj.satelline = satelline;
    obj.id = id;
    obj.checked = checked;     
    obj.link = sLink;//: link hình ảnh hiển thị Phương tiện.
    obj.stoptime = stoptime;
    obj.losttime = losttime;
    obj.driverphone = driverphone;
    obj.direction = direction;    
    //obj.temperature=temperature;
    //obj.intensity=intensity;
    obj.sumDistance=sumdistance; // tong khoang cach
    //obj.ad1=ad1;
    obj.ad2=ad2;
    obj.input1=input1;
    obj.input2=input2;
    obj.input3=input3;
    obj.input4=input4;
    obj.input5=input5;
    obj.volume=volume;
    obj.fuel=fuel;
    // ĐậmPV: 2010-10-11 - Add: trạng thái nguồn
    obj.power_status = power;
    obj.power_id = power_id;
    obj.active=active;
    obj.trucktype=trucktype;
    obj.mapid = mapid;
    
    return obj;
}
function CreateNewDeviceName(name, id,driver,driverphone)
{
    var obj=new Object();
    obj.name = name;// : Phương tiện;
    obj.id = id;
    obj.driver=driver;
    obj.driverphone=driverphone;
    return obj;
}
//******************************************************************************
    function toHIS(tm)
    {
         try
         {
             var arr = tm.split(" ");
             return arr[1];
         }
         catch(e)
         {
             return tm;
         }
    }
    function conDee2Dec(coor, type)    //Chuyen do-phut sang so thap phan
    {
        try
        {
            var nDee = coor.substring(0, (type == "lat" ? 2 : 3));
            var nMin = coor.substring((type == "lat" ? 2 : 3), (type == "lat" ? 4 : 5)) + "." + coor.substring((type == "lat" ? 4 : 5));
            //alert(coor + " " + nDee + " " + nMin);
            return parseFloat(parseFloat(nDee) + (parseFloat(nMin) / 60)).toString();
        }
        catch(e)
        {
            return (type == "lat" ? "00000000" : "000000000");
        }
    }
    function toMDYHISJS(str)
    {
        try
        {    
            //alert("1");
            var arr1 = new Array();
            arr1 = str.split(" ");
            //alert("2");
            var arr2 = new Array();
            arr2 = arr1[0].toString().split("-");
            //alert("3");
            return arr2[1] + "/" + arr2[2] + "/" + arr2[0] + " " + arr1[1];
        }
        catch(e)
        {
            return str;
        }
    }
    function CustomGetTileUrl(a,b)
    {
        return "http://map2.vngeobiz.com/tilemap/tilemapservice?lvl=" + b + "&top="+ a.y + "&left=" + a.x + "&type=vector";
        //return "file:///C:/Documents and Settings/T61P/Desktop/Google/Google/Z" + b + "/" + a.y + "_" + a.x + ".png"; // replace that with a "real" URL
    }
function oHandler()
{
//alert('koko');
    oHandler = $("#img").msDropDown();    
}
function selectAngle(angle, type)
{
    if(type == 3)    //Mat tin hieu
    {
        if(angle <= 22 || angle > 338)
            return "xam000.gif";
        else if(angle > 22 && angle <= 67)
            return "xam045.gif";
        else if(angle > 67 && angle <= 112)
            return "xam090.gif";
        else if(angle > 112 && angle <= 157)
            return "xam135.gif";
        else if(angle > 157 && angle <= 202)
            return "xam180.gif";
        else if(angle > 202 && angle <= 247)
            return "xam225.gif";
        else if(angle > 247 && angle <= 292)
            return "xam270.gif";
        else
            return "xam315.gif";
    }
    else if(type == 0)
    {
        if(angle <= 22 || angle > 338)
            return "xanh000.gif";
        else if(angle > 22 && angle <= 67)
            return "xanh045.gif";
        else if(angle > 67 && angle <= 112)
            return "xanh090.gif";
        else if(angle > 112 && angle <= 157)
            return "xanh135.gif";
        else if(angle > 157 && angle <= 202)
            return "xanh180.gif";
        else if(angle > 202 && angle <= 247)
            return "xanh225.gif";
        else if(angle > 247 && angle <= 292)
            return "xanh270.gif";
        else
            return "xanh315.gif";
    }
    else if(type == 1)
    {
        if(angle <= 22 || angle > 338)
            return "do000.gif";
        else if(angle > 22 && angle <= 67)
            return "do045.gif";
        else if(angle > 67 && angle <= 112)
            return "do090.gif";
        else if(angle > 112 && angle <= 157)
            return "do135.gif";
        else if(angle > 157 && angle <= 202)
            return "do180.gif";
        else if(angle > 202 && angle <= 247)
            return "do225.gif";
        else if(angle > 247 && angle <= 292)
            return "do270.gif";
        else
            return "do315.gif";
    }
    else if(type == 2)
    {
        if(angle <= 22 || angle > 338)
            return "vang000.gif";
        else if(angle > 22 && angle <= 67)
            return "vang045.gif";
        else if(angle > 67 && angle <= 112)
            return "vang090.gif";
        else if(angle > 112 && angle <= 157)
            return "vang135.gif";
        else if(angle > 157 && angle <= 202)
            return "vang180.gif";
        else if(angle > 202 && angle <= 247)
            return "vang225.gif";
        else if(angle > 247 && angle <= 292)
            return "vang270.gif";
        else
            return "vang315.gif";
    }
    else
    {
        return "xam045.gif";
    }
}  
function GetVBDTile(a, b)
 {
    var q = Math.floor((Math.pow(2, b) * a.y + a.x) / 10000);
    return "http://www.vietbando.com/maps/mapimages/" + b + "/" + q + "/" + a.y + "_" + a.x + ".png";
 }  